﻿using FluentAssertions;
using LINQPad.OpenAccess.Metadata.Reflection.Adapters;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Telerik.OpenAccess.Metadata;

namespace LINQPad.OpenAccess.Tests.Metadata.Reflection.Adapters
{
    [TestClass]
    public class ContextTypeInfoAdapterFixture
    {
        private readonly ContextTypeInfoAdapter _adapter;

        public ContextTypeInfoAdapterFixture( )
        {
            this._adapter = new ContextTypeInfoAdapter( );
        }

        [TestMethod]
        public void TestAdaptForAttributesContextType( )
        {
            var result = this._adapter.Adapt( typeof( TestModel.Attributes.SofiaCarsRental21Model ) );
            result.Should( ).NotBeNull( );
            result.ContextType.Should( ).Be( typeof( TestModel.Attributes.SofiaCarsRental21Model ) );
            result.MappingType.Should( ).Be( MappingDefinitionType.Attributes );
            result.Name.Should( ).Be( typeof( TestModel.Attributes.SofiaCarsRental21Model ).Name );
            result.DefaultBackendConfiguration.Should( ).NotBeNull( );
            result.DefaultMetadataSource.Should( )
                                        .NotBeNull( )
                                        .And.BeOfType<AttributesMetadataSource>( );
        }
        [TestMethod]
        public void TestAdaptForFluentContextType( )
        {
            var result = this._adapter.Adapt( typeof( TestModel.Fluent.SofiaCarsRental21Model ) );
            result.Should( ).NotBeNull( );
            result.ContextType.Should( ).Be( typeof( TestModel.Fluent.SofiaCarsRental21Model ) );
            result.MappingType.Should( ).Be( MappingDefinitionType.Fluent );
            result.Name.Should( ).Be( typeof( TestModel.Fluent.SofiaCarsRental21Model ).Name );
            result.DefaultBackendConfiguration.Should( ).NotBeNull( );
            result.DefaultMetadataSource.Should( )
                                        .NotBeNull( )
                                        .And.BeOfType<TestModel.Fluent.SofiaCarsRental21ModelFluentMetadataSource>( );
        }
        [TestMethod]
        public void TestAdaptForXmlContextType( )
        {
            var result = this._adapter.Adapt( typeof( TestModel.Xml.SofiaCarsRental21Model ) );
            result.Should( ).NotBeNull( );
            result.ContextType.Should( ).Be( typeof( TestModel.Xml.SofiaCarsRental21Model ) );
            result.MappingType.Should( ).Be( MappingDefinitionType.Xml );
            result.Name.Should( ).Be( typeof( TestModel.Xml.SofiaCarsRental21Model ).Name );
            result.DefaultBackendConfiguration.Should( ).NotBeNull( );
            result.DefaultMetadataSource.Should( )
                                        .NotBeNull( )
                                        .And.BeOfType<XmlMetadataSource>( );
        }
    }
}